<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业5</title>
    <style>
        div {
            float: left;
            width: 200px;
            height: 200px;
        }
    </style>
</head>

<body>
    <script>
        function randomColor(setv = 0) {
            let randomNum = [
                Math.floor(Math.random() * (255 + 1)),
                Math.floor(Math.random() * (255 + 1)),
                Math.floor(Math.random() * (255 + 1))
            ]
            // let randomNum = Math.floor(Math.random() * (255 + 1))
            // let randomNum1 = Math.floor(Math.random() * (255 + 1))
            // let randomNum2 = Math.floor(Math.random() * (255 + 1))
            if (setv === 0) {
                console.log(`rgb(${randomNum[0]},${randomNum[1]},${randomNum[2]})`)
                return (`rgb(${randomNum[0]},${randomNum[1]},${randomNum[2]})`)
            } else if (setv === 1) {
                let randomNum_T = []
                for (i = 0; i < randomNum.length; i++) {
                    if (randomNum[i] < 16) {
                        randomNum_T.push('0' + randomNum[i].toString(16))
                    } else {
                        randomNum_T.push(randomNum[i].toString(16))
                    }
                }
                console.log(`#${randomNum_T[0]}${randomNum_T[1]}${randomNum_T[2]}`)
                return (`#${randomNum_T[0]}${randomNum_T[1]}${randomNum_T[2]}`)
            }
        }
        document.write(`
        <div style="background-color: ${randomColor()};"></div>
        <div style="background-color: ${randomColor(0)};"></div>
        <div style="background-color: ${randomColor(1)};"></div>
        `)
    </script>
</body>

</html>